<?php
namespace User\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){
		$test = M('cate');
		$list = $test->order('id')->select();
		$this->list = $list;
		$this->display();
    }
	public function upload(){
		$setting=C('UPLOAD_SITEIMG_QINIU');
		$Upload = new \Think\Upload($setting);
		$Upload->subName = 'userid';  //创建子目录
		$Upload->saveName = date('Y-m-d').'_'.uniqid();		//以当前时间戳命新图片
		$info = $Upload->upload(); //开始上传
		$photo = M('Photo');
		$data['url'] = $info["picdata"]["url"]; //获取图片地址
		//$data['url'] = $info["picdata"]["savename"]; //获取图片名称
		//$data['url'] = I('pictitle');
		$list = $photo->add($data);
		$in = array();
		$in['state'] = "SUCCESS";
			echo json_encode($in); //成功提示
	}
	public function UpMovie(){
		$this->display();
	}
	public function userUpload(){
		$savePath = './';  //图片存储路径
		$savePicName = 'user_';  //图片存储名称
		$file_src = $savePath.$savePicName."_src.jpg";
		$filename162 = $savePath.$savePicName."_162.jpg";
		$filename48 = $savePath.$savePicName."_48.jpg";
		$filename20 = $savePath.$savePicName."_20.jpg";

		$src=base64_decode($_POST['pic']);
		$pic1=base64_decode($_POST['pic1']);
		$pic2=base64_decode($_POST['pic2']);
		//$pic3=base64_decode($_POST['pic3']);

		if($src) {
			file_put_contents($file_src,$src);
		}

		file_put_contents($filename162,$pic1);
		file_put_contents($filename48,$pic2);
		//file_put_contents($filename20,$pic3);

		$rs['status'] = 1;
		$rs['picUrl'] = $savePath.$savePicName;

		print json_encode($rs);
}

	public function del(){
		$setting=C('UPLOAD_SITEIMG_QINIU');
		$up = new \Think\Upload\Driver\Qiniu\QiniuStorage($setting['driverConfig']);
		//$file = array('userid_2014-06-26_53abe0ff7c8d9.gif','userid_2014-06-26_53abe101734d9.gif','userid_2014-06-26_53abe102ee207.gif','userid_2014-06-26_53abe105a0c59.gif','userid_2014-06-26_53abe106e564a.gif');
		//批量删除
	//	$ups = $up->delBatch($file);
	//删除单个文件
	//$ups = $up->del($file);
		dump($ups);
	}
	public function youku(){
		$json= file_get_contents('https://openapi.youku.com/v2/videos/show_basic_batch.json?client_id=69b6e122da21a2d5&video_ids=XNzE2ODIxNDg0,XNjAwMjU5Nzc2,XNDg1NDQ5MzU2');
		$this->voa = json_decode($json, true);
		dump($this->voa);
		$list = $this->voa['videos'];
		$this->assign('list',$list);
		$this->display();
	}
}